<template>
  <base-breadcrumb :breadcrumb="!isAudit">
    <a-card>
      <titleName title="基本信息"></titleName>
      <a-form-model
        ref="ruleForm"
        :model="form"
        :rules="rules"
        :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapperCol="{ lg: { span: 16 }, sm: { span: 16 } }"
      >
        <a-row :gutter="24">
          <a-col
            :md="16"
            :sm="16"
          >
            <a-form-model-item
              label="所属单位"
              prop="project"
              :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapperCol="{ lg: { span: 16 }, sm: { span: 16 } }"
            >
              <org-tree-select
                v-model="form.projectId"
                :disabled="pageType == 'look'"
                isAutoSelectFirst
                checkStrictly
                @select="selectOrg"
              ></org-tree-select>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :md="8" :sm="8">
                        <a-form-model-item label="所属分公司" prop="branchComId">
                            <SelectSubCompany
                                placeholder="请选择"
                                v-model="form.branchComId"
                                :disabled="pageType == 'look'"
                            ></SelectSubCompany>
                        </a-form-model-item>
                    </a-col>
                    <a-col :md="8" :sm="8">
                        <a-form-model-item label="所属项目" prop="projectId">
                            <SelectProject
                                placeholder="请选择"
                                v-model="form.projectId"
                                :form="form"
                                :isClear="id == ''"
                                keyValue="branchComId"
                                :disabled="pageType == 'look'"
                            ></SelectProject>
                        </a-form-model-item>
                    </a-col> -->
          <a-col
            :md="24"
            :sm="24"
            class="title"
          >一、预计总收入 （备注：预计总收入=1+5）</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                disabled
                :min="0"
                placeholder="请输入"
                :value="
                                    form.itemList[0].amountExTax +
                                    form.itemList[1].amountExTax +
                                    form.itemList[2].amountExTax +
                                    form.itemList[3].amountExTax +
                                    form.itemList[4].amountExTax +
                                    form.itemList[5].amountExTax +
                                    form.itemList[6].amountExTax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                disabled
                :min="0"
                placeholder="请输入"
                :value="
                                    form.itemList[0].tax +
                                    form.itemList[1].tax +
                                    form.itemList[2].tax +
                                    form.itemList[3].tax +
                                    form.itemList[4].tax +
                                    form.itemList[5].tax +
                                    form.itemList[6].tax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="
                                    form.itemList[0].amountExTax +
                                    form.itemList[0].tax +
                                    form.itemList[1].amountExTax +
                                    form.itemList[1].tax +
                                    form.itemList[2].amountExTax +
                                    form.itemList[2].tax +
                                    form.itemList[3].amountExTax +
                                    form.itemList[3].tax +
                                    form.itemList[4].amountExTax +
                                    form.itemList[4].tax +
                                    form.itemList[5].amountExTax +
                                    form.itemList[5].tax +
                                    form.itemList[6].amountExTax +
                                    form.itemList[6].tax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s"
          >1、合同初始收入</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[0].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[0].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[0].amountExTax + form.itemList[0].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s"
          >2、上期累计合同变更收入</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="contractTaxExclusive"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[1].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="contractAddedValueTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[1].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[1].amountExTax + form.itemList[1].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s-s"
          >当期合同变更收入</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[2].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[2].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[2].amountExTax + form.itemList[2].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s"
          >3、上期累计合同索赔收入</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[3].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[3].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[3].amountExTax + form.itemList[3].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s-s"
          >当期合同收入索赔</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[4].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[4].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[4].amountExTax + form.itemList[4].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s"
          >4、上期累计合同奖励收入</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[5].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[5].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[5].amountExTax + form.itemList[5].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s-s"
          >当期合同奖励收入 </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[6].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[6].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[6].amountExTax + form.itemList[6].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s"
          >5、调整小计（备注：调整小计=2+3+4）</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                disabled
                :min="0"
                placeholder="请输入"
                :value="
                                    form.itemList[1].amountExTax +
                                    form.itemList[2].amountExTax +
                                    form.itemList[3].amountExTax +
                                    form.itemList[4].amountExTax +
                                    form.itemList[5].amountExTax +
                                    form.itemList[6].amountExTax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                disabled
                :min="0"
                placeholder="请输入"
                :value="
                                    form.itemList[1].tax +
                                    form.itemList[2].tax +
                                    form.itemList[3].tax +
                                    form.itemList[4].tax +
                                    form.itemList[5].tax +
                                    form.itemList[6].tax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="
                                    form.itemList[1].amountExTax +
                                    form.itemList[1].tax +
                                    form.itemList[2].amountExTax +
                                    form.itemList[2].tax +
                                    form.itemList[3].amountExTax +
                                    form.itemList[3].tax +
                                    form.itemList[4].amountExTax +
                                    form.itemList[4].tax +
                                    form.itemList[5].amountExTax +
                                    form.itemList[5].tax +
                                    form.itemList[6].amountExTax +
                                    form.itemList[6].tax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title"
          >二、预计总成本（备注：预计总成本=1+2）</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                disabled
                :min="0"
                placeholder="请输入"
                :value="form.itemList[7].amountExTax + form.itemList[8].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                disabled
                :min="0"
                placeholder="请输入"
                :value="form.itemList[7].tax + form.itemList[8].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="
                                    form.itemList[7].tax +
                                    form.itemList[8].tax +
                                    form.itemList[7].amountExTax +
                                    form.itemList[8].amountExTax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s"
          >1、累计实际发生成本</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="amountExTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[7].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="tax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[7].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[7].amountExTax + form.itemList[7].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title-s"
          >2、尚需发生成本</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="不含税：(元)"
              prop="contractTaxExclusive"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[8].amountExTax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="增值税：(元)"
              prop="contractAddedValueTax"
            >
              <a-input-number
                :class="pageType == 'look' ? '' : 'inputStyl'"
                :disabled="pageType == 'look'"
                :min="0"
                placeholder="请输入"
                v-model="form.itemList[8].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item label="含税：(元)">
              <a-input-number
                :min="0"
                disabled
                :precision="2"
                placeholder="请输入"
                :value="form.itemList[8].amountExTax + form.itemList[8].tax"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title"
          >三、合同毛利</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item prop="contractTaxExclusive">
              <a-input-number
                disabled
                :min="0"
                :precision="2"
                placeholder="请输入"
                :value="
                                    form.itemList[0].amountExTax +
                                    form.itemList[0].tax +
                                    form.itemList[1].amountExTax +
                                    form.itemList[1].tax +
                                    form.itemList[2].amountExTax +
                                    form.itemList[2].tax +
                                    form.itemList[3].amountExTax +
                                    form.itemList[3].tax +
                                    form.itemList[4].amountExTax +
                                    form.itemList[4].tax +
                                    form.itemList[5].amountExTax +
                                    form.itemList[5].tax +
                                    form.itemList[6].amountExTax +
                                    form.itemList[6].tax -
                                    form.itemList[7].tax -
                                    form.itemList[8].tax -
                                    form.itemList[7].amountExTax -
                                    form.itemList[8].amountExTax
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="title"
          >四、完工进度</a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item prop="contractTaxExclusive">
              <a-input-number
                disabled
                :min="0"
                :precision="2"
                placeholder="请输入"
                :value="
                                    ((form.itemList[7].amountExTax + form.itemList[7].tax) /
                                        (form.itemList[7].amountExTax +
                                            form.itemList[7].tax +
                                            form.itemList[8].amountExTax +
                                            form.itemList[8].tax)) *
                                    100
                                        ? ((form.itemList[7].amountExTax + form.itemList[7].tax) /
                                              (form.itemList[7].amountExTax +
                                                  form.itemList[7].tax +
                                                  form.itemList[8].amountExTax +
                                                  form.itemList[8].tax)) *
                                          100
                                        : 0
                                "
              />
            </a-form-model-item>
          </a-col>
          <a-col
            v-if="pageType != 'look'"
            :md="24"
            :sm="24"
          >
            <a-form-model-item label="附件上传">
              <upload-list
                :businessCode="'BM22'"
                :uploadArrys.sync="form.fileInfoVOList"
                @fileArrysData="handleFileUploaded"
                multiple
              ></upload-list>
            </a-form-model-item>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            v-else
          >
            <a-form-model-item label="附件">
              <file-link :fileList="form.fileInfoVOList"></file-link>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>

    <template v-if="!$route.query.resolveInfo">
      <div
        class="tool-btns page-btn-right-top"
        v-if="pageType != 'look'"
      >
        <a-button
          v-if="id != '' && form.auditStatus == 'DRAFT'"
          type="danger"
          :loading="loading.DELETE"
          @click="handleSave('DELETE')"
        >删除草稿</a-button>
        <a-button
          v-if="form.auditStatus == 'REJECTED'"
          type="primary"
          :loading="loading.REJECTED"
          @click="handleSave('REJECTED')"
        >保存</a-button>
        <a-button
          v-else
          type="primary"
          :loading="loading.DRAFT"
          @click="handleSave('DRAFT')"
        >保存草稿</a-button>
        <a-button
          type="primary"
          :loading="loading.SUBMITTED"
          @click="handleSave('SUBMITTED')"
        >提交</a-button>
        <a-button
          type="primary"
          @click="handleClose"
        >关闭</a-button>
      </div>
      <div
        class="tool-btns page-btn-right-top"
        v-else
      >
        <BasePrintButton
          type="primary"
          v-if="form.auditStatus == 'PAST'"
          :beforePrintFn="checkAdjustIncomeCostPrint"
        />
        <a-button
          type="primary"
          @click="handleClose"
          class="ml20"
          v-if="checkVisibleInDetail"
        >关闭</a-button>
      </div>
    </template>
    <selectApprover
      :businessId="businessId"
      :processConfig="setProcessConfig"
    ></selectApprover>
  </base-breadcrumb>
</template>
<script>
import { getProjectInfo } from '@/api/businessAffairs/revenueAndCost'
import { addAdjustIncomeCost, editAdjustIncomeCost, delAdjustIncomeCost, checkAdjustIncomeCost, checkAdjustIncomeCostPrint } from '@/api/businessAffairs/expectRevenueAndCost'
import { getSelectListByType } from '@/api/businessAffairs/common.js'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import { isAttachment, checkVisibleInDetail } from '@/utils/util'
import { STable } from '@/components'
import UploadList from '@/components/UploadList'
import BasePrintButton from '@/components/BasePrintButton' // 打印按钮
export default {
  name: 'a' + Date.now(),
  components: {
    SelectSubCompany,
    SelectProject,
    BasePrintButton,
    UploadList
  },
  data() {
    return {
      checkVisibleInDetail: checkVisibleInDetail(this),
      loading: {
        DELETE: false,
        DRAFT: false,
        SUBMITTED: false,
        REJECTED: false
      },
      form: {
        fileInfoVOList: [],
        itemList: [
          { amountExTax: 0, id: '', sortNum: 0, tax: 0, type: 10 },
          { amountExTax: 0, id: '', sortNum: 1, tax: 0, type: 10 },
          { amountExTax: 0, id: '', sortNum: 2, tax: 0, type: 10 },
          { amountExTax: 0, id: '', sortNum: 3, tax: 0, type: 10 },
          { amountExTax: 0, id: '', sortNum: 4, tax: 0, type: 10 },
          { amountExTax: 0, id: '', sortNum: 5, tax: 0, type: 10 },
          { amountExTax: 0, id: '', sortNum: 6, tax: 0, type: 10 },
          { amountExTax: 0, id: '', sortNum: 7, tax: 0, type: 9 },
          { amountExTax: 0, id: '', sortNum: 8, tax: 0, type: 9 }
        ]
      },

      rules: {
        branchComId: [{ required: true, message: '请选择分公司' }],
        projectId: [{ required: true, message: '请选择项目' }]
      },
      id: '',
      pageType: '',
      //获取流程配置值
      processConfig: null,
      //点击提交发送流程配置值
      setProcessConfig: null,
      businessId: null
    }
  },

  async mounted() {
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      console.log(this.id)
      this.checkAdjustIncomeCostReq()
    }
    this.pageType = this.$route.query.pageType
    if (this.pageType == 'look') {
      this.$route.meta.title = '总收入与总成本调整查看'
    } else {
      this.$route.meta.title = this.id == '' ? '总收入与总成本调整新增' : '总收入与总成本调整编辑'
    }
    //获取通过获取流程配置值
    this.processConfig = await this.$getConfigFn('comm_expect_income_and_cost_adjust')
  },
  props: {
    isAudit: {
      // 是否作为审批详情
      type: Boolean,
      default: false
    }
  },
  watch: {
    isAudit: {
      immediate: true,
      handler(val) {
        if (val) {
          this.$nextTick(() => {
            this.pageType = 'look'
          })
        }
      }
    }
  },

  methods: {
    //选择单位
    selectOrg(val) {
      if (val && val.length) {
        this.form.branchComId = val[val.length - 2].orgId
      }
    },
    checkAdjustIncomeCostPrint() {
      return checkAdjustIncomeCostPrint({ id: this.id }).then((res) => {
        console.log(res)
        return res[1].data.content
      })
    },
    handleFileUploaded(list) {
      this.form.fileInfoVOList = [...list]
    },

    getTime(date, dateString, type, name) {
      this[type][name] = dateString
      console.log(this[type][name])
    },

    async checkAdjustIncomeCostReq() {
      const [err, res] = await checkAdjustIncomeCost({ id: this.id })
      if (!err) {
        this.form = res.data
      }
    },
    validateForm() {
      let flag = false
      this.$refs.ruleForm.validate((valid) => {
        if(!valid) {
          this.$message.warning("请填写完所有必填项信息")
        }
        flag = valid
      })
      return flag
    },
    isInput() {
      let flag = true
      this.form.itemList.forEach((item) => {
        if (item.tax == null || item.amountExTax == null) {
          this.$message.warning('请完善数据后提交')
          flag = false
        }
      })

      return flag
    },
    async delAdjustIncomeCost(params) {
      const [err, res] = await delAdjustIncomeCost(params)
      if (!err) {
        this.$message.success('成功')
        this.handleClose()
      }
    },
    // 处理增、删、改操作
    async handleSave(status) {
      this.setProcessConfig = null
      if (status != 'DELETE') {
        if (!this.validateForm()) return
        if (!this.isInput()) return
        if (isAttachment(this, status, this.form.fileInfoVOList)) return
      }

      if (this.loading[status]) return

      this.loading[status] = true

      const params = {
        ...this.form,
        auditStatus: status,
        id: this.$route.query.id || void 0
      }
      const { pageType } = this.$route.query
      const fn = pageType === 'edit' ? editAdjustIncomeCost : addAdjustIncomeCost
      const map = {
        DELETE: delAdjustIncomeCost,
        DRAFT: fn,
        SUBMITTED: fn,
        REJECTED: fn
      }
      console.log(status)
      console.log(map[status])
      if (status == 'DELETE') {
        let that = this
        this.$confirm({
          title: '温馨提示',
          content: '确定是否删除数据？',
          okText: '确认',
          okType: 'danger',
          cancelText: '取消',
          onOk: () => {
            return that.delAdjustIncomeCost(params)
          }
        })
        this.loading[status] = false
      } else {
        this.submitApprovalConfirm(status == 'SUBMITTED' ? this.processConfig : 6, async (flag)=>{
          if(!flag) {
            this.loading[status] = false
            return
          }
        const [err, res] = await map[status](params)
        if (!err) {
          this.$message.success('成功')
        }
        if (status == 'SUBMITTED') {
          //提交时，返回id
          this.businessId = res.data.id || this.$route.query.id
          this.setProcessConfig = this.processConfig
          return
        } else {
          this.handleClose()
        }
          this.loading[status] = false
        })
      }


    },
    handleClose() {
      console.log('23')
      if (this.isAudit) {
        window.close()
      } else {
        this.$multiTab.close(this.$route.fullpath)
      }
    }
  }
}
</script>
<style lang="less" scoped>
@deep: ~'>>>';
.tool-btns {
  display: flex;
  justify-content: flex-end;
  @{deep} .ant-btn + .ant-btn {
    margin-left: 12px;
  }
}
.title {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  font-weight: bold;
  margin-bottom: 24px;
}
.title-s {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  // margin-left: 20px;
  text-indent: 20px;
  font-weight: 500;
  margin-bottom: 24px;
}
.title-s-s {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  // margin-left: 20px;
  text-indent: 40px;
  font-weight: 500;
  margin-bottom: 24px;
}
.inputStyl {
  border-color: #e4ac0b;
  background-color: #fff9e8;
}
</style>
